/* Copyright 2009 Anthony Surma
This file is part of Java's Kademlia Extension (JKADX).

JKADX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

JKADX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JKADX.  If not, see <http://www.gnu.org/licenses/>.
*/

package jkadx.dht;

import java.util.Comparator;

/**
 * Immutable
 *
 * @author Anthony Surma
 */

public final class ContactByDistance implements Comparator <Contact>
{    
    public static final ContactByDistance[] EMPTY = new ContactByDistance[0];

    private final UniqueId target;

    public ContactByDistance(UniqueId target)
    {
	this.target = target;
    }

    @Override
    public int compare(Contact first, Contact second)
    {
	// compares first and second to see if first is closer to Id
	// than the second.
       return first.uniqueId.compareTo(second.uniqueId, target);                 
                       // returns -1 if first is closer to Id
	               // returns +1 if second is closer to Id
		       // should never return 0... I don't think it
	               // serves a purpose in this context.
    }
}